﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UE.SharePoint.ImportExport.BLL
{
    /// <summary>
    /// Extension Methods
    /// </summary>
    public static class CoreExtensions
    {   
        /// <summary>
        /// Converts the specified double value to the equivalent decimal number.
        /// </summary>
        /// <param name="oriValue"></param>
        /// <returns></returns>
        public static decimal ToDecimal(this double oriValue)
        {
            return (decimal)oriValue;
        }

        /// <summary>
        /// Indicates whether the specified string is null or an Empty string or null.
        /// </summary>
        /// <param name="oriValue"></param>
        /// <returns></returns>
        public static bool IsNullOrWhiteSpace(this string oriValue)
        {
            return string.IsNullOrEmpty(oriValue) || oriValue == "";
        } 

        /// <summary>
        /// Returns the first element that base on '#' char to split the look up value.
        /// </summary>
        /// <param name="oriValue"></param>
        /// <returns></returns>
        public static string LookUpFirst(this string oriValue,char splitStr = '#')
        {
            string[] values = oriValue.Split(splitStr);
            if (values.Length == 0)
            {
                return oriValue;
            }

            return values[0].TrimEnd(';');
        }
         
        /// <summary>
        /// Returns the second element that base on '#' char to split the look up value.
        /// </summary>
        /// <param name="oriValue"></param>
        /// <returns></returns>
        public static string LookUpLasted(this string oriValue, char splitStr = '#')
        {
            string[] values = oriValue.Split(splitStr);
            if (values.Length < 2)
            {
                return oriValue;
            }

            return values[1];
        } 
    }
}